package cn.com.qiter.minioservice.controller;

import cn.com.qiter.common.Result;
import cn.com.qiter.minioservice.service.MinioService;
import cn.com.qiter.minioservice.utils.ConstantPropertiesUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/minio/fileoss")
@CrossOrigin
public class MinioController {

    @Autowired
    private MinioService service;
    //上传头像的方法
    @PostMapping("upload")
    public Result uploadOssFile(MultipartFile file) {
        //获取上传文件  MultipartFile
        //返回上传到oss的路径
        Result url = service.putObject(ConstantPropertiesUtils.BUCKET_NAME,file,"test");
        return url;
    }
    //上传头像的方法
    @GetMapping("getObjectUrl/{filename}")
    public Result getObjectUrl(@PathVariable String filename) {
        //获取上传文件  MultipartFile
        //返回上传到oss的路径
        Result url = service.getObjectUrl(ConstantPropertiesUtils.BUCKET_NAME,filename);
        return Result.ok().data("url",url);
    }
    //上传头像的方法
    @GetMapping("presignedGetObject/{filename}")
    public Result presignedGetObject(@PathVariable String filename) {
        //获取上传文件  MultipartFile
        //返回上传到oss的路径
        Result url = service.presignedGetObject(ConstantPropertiesUtils.BUCKET_NAME,filename);
        return url;
    }
}
